package com.zhentao.redis;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@RestController
@RequestMapping("/redis")
public class RedisTest {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    //list
    @RequestMapping("/listPush")
    public String testListPush(){
        redisTemplate.opsForList(). leftPushAll("testListKey","k1","k2","k3");
        return "设置值";
    }
    @RequestMapping("/listPop")
    public String testListPop(){
        String getV=(String)  redisTemplate.opsForList().rightPop("testListKey");
        return "弹出值";
    }
    //zSet
    @RequestMapping("/zsetAdd")
    public String testZsetAdd(){

        redisTemplate.opsForZSet().add("zsetk","a",90);
        redisTemplate.opsForZSet().add("zsetk","b",93);
        redisTemplate.opsForZSet().add("zsetk","c",89);
        redisTemplate.opsForZSet().add("zsetk","d",91);
        return "zsetadd";
    }
    @RequestMapping("/zsetRange")
    public String zSetRange(){
        Set<Object> set = redisTemplate.opsForZSet().rangeByScore("zsetk",0,99);
        System.out.println(set);
        return "获取值";
    }

}
